package com.xej.taco_cloud.config;

import com.xej.taco_cloud.service.UserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;

//@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService userDetailsService;
   /*
   * 基于内存的用户存储
   */
    /*
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("buzz").password("buzz").authorities("ROLE_USER")
                .and()
                .withUser("woody").password("woody").authorities("ROLE_USER");
    }
    */


    /*
    * 基于自定义模式的用户存储
    */

    /**
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService)
                .passwordEncoder(encoder());
    }
    */

    /*
    * 拦截请求以确保用户具有相对应的权限
    */
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        http
//                .authorizeRequests()
//                    .antMatchers("/design")
//                    .access("hasRole('ROLE_USER')")
//                .antMatchers("/","/**").access("permitAll()");
//    }
//
//    @Bean
//    public PasswordEncoder encoder(){
//        return new StandardPasswordEncoder("53cr3t");
//    }
}
